﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

using CorreoSocialWeb.Models;
using Subgurim.Controles;

namespace CorreoSocialWeb.Views
{
    public class CoordenadasDeSesionHelper 
    {
        private Page Page { get; set; }

        public bool SonValidas
        { 
            get
            {
                if (this.SinOrigen)
                    return false;

                if (this.SinDestino)
                    return false;

                if (this.Origen == new GLatLng())
                    return false;

                if (this.Destino == new GLatLng())
                    return false;

                return true;
            }
        }

        public bool SinDatos
        {
            get
            {
                return this.SinDestino && this.SinOrigen;
            }
        }

        public CoordenadasDeSesionHelper(Page page)
        {
            this.Page = page;
        }

        public void Borrar()
        {
            this.Origen = this.Destino = null;
        }

        public void Cargar(IOrigenDestinoLatLong item)
        {
            this.Origen = new GLatLng(item.OrigenLatitud, item.OrigenLongitud);
            this.Destino = new GLatLng(item.DestinoLatitud, item.DestinoLongitud);
        }

        public bool SinDestino
        {
            get
            {
                return this.Destino == null || this.Destino.Equals(new GLatLng(0, 0));
            }
        }

        public bool SinOrigen
        {
            get
            {
                return this.Origen == null || this.Origen.Equals(new GLatLng(0, 0));
            }
        }

        public GLatLng Destino
        {
            get
            {
                return this.Page.Session["gpsDestino"] as GLatLng;
            }
            set
            {
                this.Page.Session["gpsDestino"] = value;
            }
        }

        public GLatLng Origen
        {
            get
            {
                return this.Page.Session["gpsOrigen"] as GLatLng;
            }
            set
            {
                this.Page.Session["gpsOrigen"] = value;
            }
        }
    }
}